<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1,.box2{
            width: 200px;
            height: 200px;
            background-color: green;
        }
        .box2{
            background-color: pink;
        }
    </style>
</head>
<body>
    <div class="box1">
        
    </div>
    <div class="box2" onclick="foo(this)">

    </div>
    <script>
        var box1 = document.querySelector('.box1');
        var box2 = document.querySelector('.box2');

        // 其一：匿名函数绑定
        box1.onclick = function () {
            this.style.backgroundColor = 'red'
        }

        // 其二：行内绑定
        function foo(that) {
            that.style.backgroundColor = 'green'
        }

        // 其三：事件句柄绑定
        box2.addEventListener('mouseover', function () {
            console.log(this);
        })
        
    </script>
</body>
</html>